if(typeof emoneysoft == "undefined") var emoneysoft = new Object();
if(typeof emoneysoft.FusionChartsUtil == "undefined") emoneysoft.FusionChartsUtil = new Object();
emoneysoft.FusionCharts = function(swf, id,containterDiv, w, h, debugMode, registerWithJS, c, scaleMode, lang){
	if (!document.getElementById) { return; }
	this.initialDataSet = false;
	this.params = new Object();this.variables = new Object();this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }if(id) { this.setAttribute('id', id); }
	if(containterDiv){this.setAttribute('containter', containterDiv);}
	if(w) { this.setAttribute('width', w); }if(h) { this.setAttribute('height', h); }
	if(c) { this.addParam('bgcolor', c); }this.addParam('menu', 'false');
	this.addParam('quality', 'high');this.addParam('wmode', 'Opaque');//window
	this.addParam('allowScriptAccess', 'always');
	if(w.toString().indexOf("%")!=-1 || h.toString().indexOf("%")!=-1){
	    this.addVariable('chartWidth', "whole");this.addVariable('chartHeight', "whole");
	}else{	
	    this.addVariable('chartWidth', w.toString().toLowerCase().replace("px",""));
	    this.addVariable('chartHeight', h.toString().toLowerCase().replace("px",""));
	}
	debugMode = debugMode ? debugMode : 0;	this.addVariable('debugMode', debugMode);
	this.addVariable('domid', id);
	registerWithJS = registerWithJS ? registerWithJS : 0;this.addVariable('registerWithJS', registerWithJS);
	scaleMode = scaleMode ? scaleMode : 'noScale';this.addVariable('scaleMode', scaleMode);
	lang = lang ? lang : 'EN';this.addVariable('lang', lang);
}
emoneysoft.FusionCharts.prototype = {
    setAttribute: function (name, value) { this.attributes[name] = value; },
    getAttribute: function (name) { return this.attributes[name]; },
    addParam: function (name, value) { this.params[name] = value; },
    getParams: function () { return this.params; },
    addVariable: function (name, value) { this.variables[name] = value; },
    getVariable: function (name) { return this.variables[name]; },
    getVariables: function () { return this.variables; },
    getVariablePairs: function () {
        var variablePairs = new Array(); var key; var variables = this.getVariables();
        for (key in variables) { variablePairs.push(key + "=" + variables[key]); } return variablePairs;
    },
    getSWFHTML: function () {
        var swfNode = "";
        if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
            // netscape plugin architecture			
            swfNode = '<embed type="application/x-shockwave-flash" menu="' + this.getAttribute('menu') + '" src="' + this.getAttribute('swf') + '" width="' + this.getAttribute('width') + '" height="' + this.getAttribute('height') + '"  ';
            swfNode += ' id="' + this.getAttribute('id') + '" name="' + this.getAttribute('id') + '" ';
            var params = this.getParams();
            for (var key in params) { swfNode += [key] + '="' + params[key] + '" '; }
            var pairs = this.getVariablePairs().join("&");
            if (pairs.length > 0) { swfNode += 'flashvars="' + pairs + '"'; }
            swfNode += '/>';
        } else { // PC IE			
            swfNode = '<object z-index="999" id="' + this.getAttribute('id') + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getAttribute('width') + '" height="' + this.getAttribute('height') + '">';
            swfNode += '<param name="movie" value="' + this.getAttribute('swf') + '" />';
            var params = this.getParams();
            for (var key in params) {
                swfNode += '<param name="' + key + '" value="' + params[key] + '" />';
            }
            var pairs = this.getVariablePairs().join("&");
            if (pairs.length > 0) { swfNode += '<param name="flashvars" value="' + pairs + '" />'; }
            swfNode += "</object>";
        }
        //alert(swfNode);
        return swfNode;
    },
    setDataURL: function (strDataURL) {
        if (this.initialDataSet == false) {
            this.addVariable('dataURL', strDataURL);
            this.initialDataSet = true;
        }
    },
    setDataXML: function (strDataXML) {
        if (this.initialDataSet == false) {
            this.addVariable('dataXML', strDataXML);
            this.initialDataSet = true;
        }
    },
    refreshUrl: function (df, url) {
        var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
        chartObj.RenderUrl(df, url);
    },
    refreshData: function (f, strDataXML) {
        //        var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
        //        if (chartObj.RefreshData == undefined) return false;
        //        chartObj.RefreshData(f, strDataXML);
        //        return true;
        try {
            var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
            chartObj.RefreshData(f, strDataXML);
            //alert(f+"|"+strDataXML);
            //alert("refreshData.true");
            return true;
        }
        catch (ex) {
            //alert("refreshData.false");
            return false;
        }
    },
    isReady: function () {
        var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
        return chartObj.RefreshData != undefined;
    },
    render: function () {
        var elementId = this.getAttribute('containter');
        var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
        n.innerHTML = this.getSWFHTML();
        return true;
    },
    clear: function () {
        var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
        chartObj.clearChart();
        emoneysoft.FusionChartsUtil.cleanupSWFs();
        var elementId = this.getAttribute('containter');
        var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
        n.innerHTML = "";
        this.attributes = null;
        this.params = null;
        this.variables = null;
    },
    resize: function (w1, h1) {
        var chartObj = emoneysoft.FusionChartsUtil.getChartObject(this.getAttribute('id'));
        chartObj.ChangeSize(w1, h1);
        chartObj.style.width = w1 + "px";
        chartObj.style.height = h1 + "px";
    },
    getVer: function () {
        this.installedVer = emoneysoft.FusionChartsUtil.getPlayerVersion();
        return this.installedVer.major;
    }
}
/* ---- detection functions ---- */
emoneysoft.FusionChartsUtil.getPlayerVersion = function(){
	var PlayerVersion = new emoneysoft.PlayerVersion([-1,-1,-1]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new emoneysoft.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ 
		//If Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
				PlayerVersion = new emoneysoft.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { 
		// Win IE (non mobile)
		// Do minor version lookup in IE, but avoid Flash Player 6 crashing issues
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new emoneysoft.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new emoneysoft.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
emoneysoft.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}

// ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
/* Fix for video streaming bug */
emoneysoft.FusionChartsUtil.cleanupSWFs = function() {
	if (window.opera || !document.all) return;
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// Fixes bug in fp9
emoneysoft.FusionChartsUtil.prepUnload = function() {
	__flash_unloadHandler = function(){};
	__flash_savedUnloadHandler = function(){};
	if (typeof window.onunload == 'function') {
		var oldUnload = window.onunload;
		window.onunload = function() {
			emoneysoft.FusionChartsUtil.cleanupSWFs();
			oldUnload();
		}
	} else {
		window.onunload = emoneysoft.FusionChartsUtil.cleanupSWFs;
	}
}
if (typeof window.onbeforeunload == 'function') {
	var oldBeforeUnload = window.onbeforeunload;
	window.onbeforeunload = function() {
		emoneysoft.FusionChartsUtil.prepUnload();
		oldBeforeUnload();
	}
} else {
	window.onbeforeunload = emoneysoft.FusionChartsUtil.prepUnload;
}

/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* Function to return Flash Object from ID */
emoneysoft.FusionChartsUtil.getChartObject = function(id)
{
  if (window.document[id]) {
      return window.document[id];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[id])
      return document.embeds[id]; 
  } else {
    return document.getElementById(id);
  }
}
/* Aliases for easy usage */
var getChartFromId = emoneysoft.FusionChartsUtil.getChartObject;
var FusionCharts = emoneysoft.FusionCharts;
